package com.yaolong.api.modules.opms.controller;

import cn.hutool.extra.servlet.ServletUtil;
//import com.yaolong.api.modules.opms.entity.OpmsDistressAttach;
import com.yaolong.api.modules.opms.entity.OpmsDistressRelief;
import com.yaolong.api.modules.opms.service.OpmsDistressReliefService;
import com.yaolong.commons.response.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import com.yaolong.commons.base2.BaseController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 困难救助表 前端控制器
 * </p>
 *
 * @author yaolonga
 * @version v1.0.0
 * @since 2023-02-19
 */
@RestController
@RequestMapping("/api/distress/opms-distress-relief")
@Api(tags = "困难救助管理")
public class OpmsDistressReliefController extends BaseController<OpmsDistressRelief, OpmsDistressReliefService> {


    @Autowired
    private OpmsDistressReliefService opmsDistressReliefService;


    @Value("${filePath}")
    private String filePath;

    /*文件上传*/


    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    @ApiOperation(value = "上传", notes = "上传")
    @ResponseBody
    public Map<String,Object> uploadFile(MultipartFile file) throws Exception {
        return opmsDistressReliefService.uploadAttach(file);
    }


    @PostMapping("/download")
    public void downLoad(String name, HttpServletResponse response) {
        try {
            response.setCharacterEncoding("UTF-8");
            ServletUtil.write(response, new File(filePath + name));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
